package com.ncmmall.component.schedule.bootstrap;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.util.Properties;

/**
 *
 */
public class LogoAscil {

    public void imageToASCII() {
        try {

            Properties prop = new Properties();
            InputStream in = Object.class.getResourceAsStream("/application.properties");
            prop.load(in);

            File f = new File(prop.getProperty("logo.path").trim());

            BufferedImage img1 = ImageIO.read(f);
            int h = img1.getHeight();
            int w = img1.getWidth();
            char[][] gray = new char[h][w + 2];
            for (int x = 0; x < h; x = x + 9) {
                for (int y = 0; y < w; y = y + 4) {
                    int argb = img1.getRGB(y, x);
                    int r = (argb >> 16) & 0xFF;
                    int g = (argb >> 8) & 0xFF;
                    int b = (argb >> 0) & 0xFF;
                    int grayPixel = (int) (0.299 * r + 0.587 * g + 0.114 * b);
                    if (grayPixel >= 230) gray[x][y] = ' ';
                    else gray[x][y] = '#';

                    System.out.print(gray[x][y]);
                }
                gray[x][w] = '\r';
                gray[x][w + 1] = '\n';
                System.out.println();
            }
        } catch (Exception e) {
            //do nothing
        }
    }


}
